/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.lottery.game.controller.v2.advert;


import com.lottery.game.common.Response;
import com.lottery.game.core.modules.entity.user.FrontPicturePojo;
import com.lottery.game.core.modules.service.app.FrontPictureService;
import com.lottery.game.core.modules.service.game.SysDictService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;


/**
 * 前台滚动图片设置Controller
 * @author sss
 * @version 2018-05-11
 */
@Slf4j
@RestController
@RequestMapping(value="/api/v2/advert")
@Api(tags="APP-首页轮播图片")
public class AdvertController {

		@Autowired
	  private SysDictService sysDictService;

		private String imageServerAddress;

		@Autowired
		private FrontPictureService frontPictureService;

    @SuppressWarnings("unchecked")
		@ApiOperation(value = "获取图片列表", notes = "获取图片列表", httpMethod="GET")
		@GetMapping(value="/pictures", produces= {MediaType.APPLICATION_JSON_UTF8_VALUE})
		public Response<List<FrontPicturePojo>> getPicture() {
				return Response.build(dealPicture(frontPictureService.getAllPicture()));
		}

		private List<FrontPicturePojo> dealPicture(List<FrontPicturePojo> frontPicturePojos) {
    	 for (FrontPicturePojo picturePojo : frontPicturePojos) {
    	 	  picturePojo.setPictureAddress(getImageServer() + picturePojo.getPictureAddress());
			 }
    	 return frontPicturePojos;
		}

		private String getImageServer() {
			if (imageServerAddress != null) {
				return imageServerAddress;
			}
			return imageServerAddress = sysDictService.findImageServerAddress();
		}
}
